package com.china08.yxyapi.api.home.index.resource;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.es.ElasticYxyResResource;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.yxyresource.YxyResourceService;

/**
 * 首页--精品资源
 * 
 */
@CrossOrigin
@RestController
public class IndexSrhResourceController {

    @Autowired
    private YxyResourceService ysr;

    @ResponseBody
    @RequestMapping(value = "/api_yw/home/index/resource", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(@RequestBody RepModel reqModel) {
        String areaId = reqModel.areaId;
        List<RespModel> list = new ArrayList<RespModel>();
        List<ElasticYxyResResource> elasticYxyResResourceLst = ysr.homeIndexResourceTop(areaId, 8);

        for (ElasticYxyResResource elasticYxyResResource : elasticYxyResResourceLst) {
            RespModel respModel = new RespModel();
            respModel.title = elasticYxyResResource.getTitle();
            respModel.uploadName = elasticYxyResResource.getUploaderName();
            respModel.fileSize = elasticYxyResResource.getFileSize();
            respModel.formatId = elasticYxyResResource.getFormatId();
            respModel.resId = elasticYxyResResource.getId();
            list.add(respModel);
        }
        return list;
    }

    protected static class RepModel extends YxyApiReqModel {
        // 区域Id码
        public String areaId;

    }

    protected static class RespModel extends YxyApiRespModel {

        public String resId;// 微课id

        public String title;// 标题

        public String uploadName;// 上传者名称

        public Integer fileSize;// 浏览量

        public String formatId; // 格式Id

    }
}
